package com.isi.mtl.lf.jag.parameters;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;

import com.isi.mtl.lf.jag.constantes.Languages;
import com.isi.mtl.lf.jag.constantes.Travel_Modes;

/**
 * 
 * @author Loic FALKLAND
 * @version 1.0
 *
 */
 

public class DirectionParameter extends Parameter{

	private Integer travel_Mode = Travel_Modes.DRIVING;
	private Integer language = Languages.ENGLISH;
	private HashMap<Integer, String> travelModeMapping;
	private HashMap<Integer, String> languageMapping;
	private List<String> waypoints;

	
	public DirectionParameter(){
		super();
	}
	
	/**
	 * 
	 * @param from starting point
	 * @param to destination point
	 * 
	 */
	public DirectionParameter(String from, String to) {
		super(from, to);
	}
	
	/**
	 * 
	 * @param from starting point
	 * @param to destination point
	 * @param language indicates the language of output <br/><a href="https://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1" target="_blank">More information</a>
	 */
	public DirectionParameter(String from, String to,
			Integer language) {
		super(from, to);
		this.language = language;
	}
	
	/**
	 * 
	 * @param from starting point
	 * @param to destination point
	 * @param travel_Mode mode of transport depends on Travel_Modes' constant
	 * @param language indicates the language of output <br/><a href="https://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1" target="_blank">More information</a>
	 */
	public DirectionParameter(String from, String to, Integer travel_Mode,
			Integer language, Integer metric) {
		super(from, to, metric);
		this.travel_Mode = travel_Mode;
		this.language = language;
	}
	
	/**
	 * 
	 * @param from starting point
	 * @param to destination point
	 * @param waypoints List of String that contains the stop-over values
	 *
	 */
	public DirectionParameter(String from, String to, List<String> waypoints) {
		super(from, to);
		this.waypoints = waypoints;
	}

	/**
	 * 
	 * @param from starting point
	 * @param to destination point
	 * @param travel_Mode mode of transport depends on Travel_Modes' constant
	 * @param language indicates the language of output <br/><a href="https://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1" target="_blank">More information</a>
	 * @param secure_transaction indicates if you want a secure transaction (https / http)
	 * @param sensor indicate whether your application is using a sensor (such as a GPS locator) <br/><a href="https://developers.google.com/maps/documentation/" target="_blank">More information</a>
	 * 
	 */
	public DirectionParameter(String from, String to, Integer travel_Mode,
			Integer language, Integer metric, Boolean secure_transaction, Boolean sensor) {
		super(from, to, secure_transaction, sensor, metric);
		this.travel_Mode = travel_Mode;
		this.language = language;
	}
	
	/**
	 * 
	 * @param from starting point
	 * @param to destination point
	 * @param travel_Mode mode of transport depends on Travel_Modes' constant
	 * @param language indicates the language of output <br/><a href="https://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1" target="_blank">More information</a>
	 * @param metric depends on Unit constant
	 * @param secure_transaction indicates if you want a secure transaction (https / http)
	 * 
	 */
	public DirectionParameter(String from, String to, Integer travel_Mode,
			Integer language, Integer metric, Boolean secure_transaction) {
		super(from, to, secure_transaction);
		this.travel_Mode = travel_Mode;
		this.language = language;
	}
	
	/**
	 * 
	 * @param from starting point
	 * @param to destination point
	 * @param waypoints List of String that contains the stop-over values
	 * @param travel_Mode mode of transport depends on Travel_Modes' constant
	 * @param language indicates the language of output <br/><a href="https://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1" target="_blank">More information</a>
	 * @param secure_transaction indicates if you want a secure transaction (https / http)
	 * @param sensor indicate whether your application is using a sensor (such as a GPS locator) <br/><a href="https://developers.google.com/maps/documentation/" target="_blank">More information</a>
	 * 
	 */
	public DirectionParameter(String from, String to, List<String> waypoints, Integer travel_Mode,
			Integer language, Integer metric, Boolean secure_transaction, Boolean sensor) {
		super(from, to, secure_transaction, sensor, metric);
		this.travel_Mode = travel_Mode;
		this.language = language;
		this.waypoints = waypoints;
	}
	
	/**
	 * 
	 * @param from starting point
	 * @param to destination point
	 * @param waypoints List of String that contains the stop-over values
	 * @param travel_Mode mode of transport depends on Travel_Modes' constant
	 * @param language indicates the language of output <br/><a href="https://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1" target="_blank">More information</a>
	 * 
	 */
	public DirectionParameter(String from, String to, List<String> waypoints, Integer travel_Mode,
			Integer language, Integer metric) {
		super(from, to, metric);
		this.travel_Mode = travel_Mode;
		this.language = language;
		this.waypoints = waypoints;
	}

	
	{
		
		//Setting mapping du mode de travel
		travelModeMapping = new HashMap<Integer, String>();
		travelModeMapping.put(Travel_Modes.DRIVING, "driving");
		travelModeMapping.put(Travel_Modes.WALKING, "walking");
		travelModeMapping.put(Travel_Modes.BICYCLING, "bicycling");
		travelModeMapping.put(Travel_Modes.TRANSIT, "transit");
		
		//Setting mapping de la langue
		languageMapping = new HashMap<Integer, String>();
		languageMapping.put(Languages.ARABIC, "ar");
		languageMapping.put(Languages.BASQUE, "eu");
		languageMapping.put(Languages.BULGARIAN, "bg");
		languageMapping.put(Languages.BENGALI, "bn");
		languageMapping.put(Languages.CATALAN, "ca");
		languageMapping.put(Languages.CZECH, "cs");
		languageMapping.put(Languages.DANISH, "da");
		languageMapping.put(Languages.GERMAN, "de");
		languageMapping.put(Languages.GREEK, "el");
		languageMapping.put(Languages.ENGLISH, "en");
		languageMapping.put(Languages.ENGLISH_AUSTRALIAN, "en-AU");
		languageMapping.put(Languages.ENGLISH_GB, "en-GB");
		languageMapping.put(Languages.SPANISH, "es");
		languageMapping.put(Languages.FARSI, "fa");
		languageMapping.put(Languages.FINNISH, "fi");
		languageMapping.put(Languages.FILIPINO, "fil");
		languageMapping.put(Languages.FRENCH, "fr");
		languageMapping.put(Languages.GALICIAN, "gl");
		languageMapping.put(Languages.GUJARATI, "gu");
		languageMapping.put(Languages.HINDI, "hi");
		languageMapping.put(Languages.CROATIAN, "hr");
		languageMapping.put(Languages.HUNGARIAN, "hu");
		languageMapping.put(Languages.INDONESIAN, "id");
		languageMapping.put(Languages.ITALIAN, "it");
		languageMapping.put(Languages.HEBREW, "iw");
		languageMapping.put(Languages.JAPANESE, "ja");
		languageMapping.put(Languages.KANNADA, "kn");
		languageMapping.put(Languages.KOREAN, "ko");
		languageMapping.put(Languages.LITHUANIAN, "lt");
		languageMapping.put(Languages.LATVIAN, "lv");
		languageMapping.put(Languages.MALAYALAM, "ml");
		languageMapping.put(Languages.MARATHI, "mr");
		languageMapping.put(Languages.DUTCH, "nl");
		languageMapping.put(Languages.NORWEGIAN, "no");
		languageMapping.put(Languages.POLISH, "pl");
		languageMapping.put(Languages.PORTUGUESE, "pt");
		languageMapping.put(Languages.PORTUGUESE_BR, "pt-BR");
		languageMapping.put(Languages.PORTUGUESE_PT, "pt-PT");
		languageMapping.put(Languages.ROMANIAN, "ro");
		languageMapping.put(Languages.RUSSIAN, "ru");
		languageMapping.put(Languages.SLOVAK, "sk");
		languageMapping.put(Languages.SLOVENIAN, "sl");
		languageMapping.put(Languages.SERBIAN, "sr");
		languageMapping.put(Languages.SWEDISH, "sv");
		languageMapping.put(Languages.TAGALOG, "tl");
		languageMapping.put(Languages.TAMIL, "ta");
		languageMapping.put(Languages.TELUGU, "te");
		languageMapping.put(Languages.THAI, "th");
		languageMapping.put(Languages.TURKISH, "tr");
		languageMapping.put(Languages.UKRAINIAN, "uk");
		languageMapping.put(Languages.VIETNAMESE, "vi");
		languageMapping.put(Languages.CHINESE_SIMPLIFIED, "zh-CN");
		languageMapping.put(Languages.CHINESE_TRADITIONAL, "zh-TW");

	}

	
	//Getters / Setters
	public Integer getTravel_Mode() {
		return travel_Mode;
	}

	public void setTravel_Mode(Integer travel_Mode) {
		this.travel_Mode = travel_Mode;
	}

	public Integer getLanguage() {
		return language;
	}

	public void setLanguage(Integer language) {
		this.language = language;
	}

	public HashMap<Integer, String> getTravelModeMapping() {
		return travelModeMapping;
	}

	public void setTravelModeMapping(HashMap<Integer, String> travelModeMapping) {
		this.travelModeMapping = travelModeMapping;
	}

	public HashMap<Integer, String> getLanguageMapping() {
		return languageMapping;
	}

	public void setLanguageMapping(HashMap<Integer, String> languageMapping) {
		this.languageMapping = languageMapping;
	}

	public String getFormattedWaypoints(){
		
		System.out.println("ici "+waypoints.size());
		
		String formattedWaypoints = "";
		
		
		if(waypoints.size() == 1){
			formattedWaypoints = waypoints.get(0);
		}
		else if(waypoints.size() > 1) {
			
		
			for(int i=0;i<waypoints.size();i++){
				
				if(i==waypoints.size()-1) {
					formattedWaypoints += waypoints.get(i);
				}
				else{
					formattedWaypoints += waypoints.get(i)+"|";
				}
				
			}
		}

		try {
			formattedWaypoints = URLEncoder.encode(formattedWaypoints, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		
		System.out.println(formattedWaypoints);
		
		return formattedWaypoints;
	
	}

	public List<String> getWaypoints() {
		return waypoints;
	}

	public void setWaypoints(List<String> waypoints) {
		this.waypoints = waypoints;
	}

	
}
